package com.kpmg.datalake.web;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.ConstVal;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.kpmg.datalake.common.constants.Constants;
import com.kpmg.datalake.common.utils.EncrypUtil;

/**
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * @since Created on azhao6 on 2018-07-30 10:28:24
 */
public class MybatisPlusGenerator {
    public static void main(String[] args) {
        generateByTables(new String[]{"PROJECT"});
    }

    private static void generateByTables(String[] tableNames) {
        GlobalConfig config = new GlobalConfig();
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.ORACLE)
            .setUrl("jdbc:oracle:thin:@10.119.169.81:1521/DTLKTS")
                .setUsername(EncrypUtil.decryptAes("gLv/jBFQwPt4NAv45QadVg==", Constants.ENCRY_KEY))
                .setPassword(EncrypUtil.decryptAes("opYmKnmNWwiRV/nlmjHvpj6adAGm0WIflXskjkym//s=", Constants.ENCRY_KEY))
                .setDriverName("oracle.jdbc.OracleDriver");
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(false)
                .setDbColumnUnderline(true)
                .setNaming(NamingStrategy.underline_to_camel)
                //修改替换成你需要的表名，多个表名传数组
                .setInclude(tableNames);
        config.setActiveRecord(false)
                //.setAuthor("alex [alex.zhao@kpmg.com]")
                .setAuthor(System.getProperty("user.name"))
                .setOutputDir(System.getProperty("user.home"))
                .setEnableCache(false)
                .setBaseColumnList(true)
                .setBaseResultMap(true)
                .setFileOverride(true);
        TemplateConfig template = new TemplateConfig();
        template.setEntity("/mptemplates/entity.java.vm");
        template.setService(ConstVal.TEMPLATE_SERVICE);
        template.setServiceImpl("/mptemplates/serviceImpl.java.vm");
        template.setMapper(ConstVal.TEMPLATE_MAPPER);
        template.setXml(ConstVal.TEMPLATE_XML);
        new AutoGenerator().setGlobalConfig(config)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setTemplate(template)
                .setPackageInfo(
                        new PackageConfig()
                                .setParent("com.kpmg.datalake")
                                .setModuleName("common")
                                .setMapper("dao")
                                .setEntity("model")
                                .setXml("mapper")
                                .setService("service")
//                                .setServiceImpl("service.impl")
                ).execute();
    }
}
